﻿/********************************************************
 * 类名：FundManageHandler.cs
 * 功能：资金
 *   ver	变更日		作者			变更内容
 * ────────────────────────────────────────
 *   V01.0	2014-02-08	李波			初版
 *
 * Copyright (c) 2013，李波版权所有
 ********************************************************/
using System;
using System.Web;
using PSS.BLL.FundManage;
using PSS.Entity.FundManage;
using PSS.Utility;

namespace PSS.WebSite.Service
{
    /// <summary>
    /// FundManageHandler 的摘要说明
    /// </summary>
    public class FundManageHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var action = StrRequest.GetQueryString("action");
                if (string.IsNullOrEmpty(action)) return;
                var method = this.GetType().GetMethod(action);
                if (method == null) return;
                object[] parameters = { context };
                method.Invoke(this, parameters);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }

        #region 收款单管理
        public void GetInitReceiptList(HttpContext context)
        {
            try
            {
                var bll = new InitReceiptBLL();
                var qcmodel = new InitReceiptQcEntity
                {
                    ReceiptSingleNo = context.Request["ReceiptSingleNo"],
                    CustomerId = context.Request["CustomerId"],
                    ReceiptSingleDateFrom = context.Request["ReceiptSingleDateFrom"],
                    ReceiptSingleDateEnd = context.Request["ReceiptSingleDateEnd"],
                    PageIndex = Convert.ToInt32(context.Request["pageIndex"]),
                    PageSize = Convert.ToInt32(context.Request["pageSize"]),
                    SortField = context.Request["sortField"],
                    SortOrder = context.Request["sortOrder"]
                };
                var json = bll.GetInitReceiptList(qcmodel);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void GetInitReceiptInfo(HttpContext context)
        {
            try
            {
                var id = context.Request["InitReceiptId"];
                if (string.IsNullOrEmpty(id)) return;
                var json = new InitReceiptBLL().GetInitReceiptInfo(id);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void GetInitReceiptDetailList(HttpContext context)
        {
            try
            {
                var bll = new InitReceiptBLL();
                var qcmodel = new InitReceiptDetailQcEntity
                {
                    InitReceiptId = context.Request["InitReceiptId"]
                };
                var json = bll.GetInitReceiptDetailList(qcmodel);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void AddInitReceipt(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new InitReceiptBLL().AddInitReceipt(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void ModifyInitReceipt(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new InitReceiptBLL().ModifyInitReceipt(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void RemoveInitReceipt(HttpContext context)
        {
            try
            {
                var id = context.Request["InitReceiptId"];
                if (string.IsNullOrEmpty(id)) return;
                var json = new InitReceiptBLL().RemoveInitReceipt(id);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        #endregion

        #region 付款单管理
        public void GetInitPayList(HttpContext context)
        {
            try
            {
                var bll = new InitPayBLL();
                var qcmodel = new InitPayQcEntity
                {
                    SinglePaymentNo = context.Request["SinglePaymentNo"],
                    VendorId = context.Request["VendorId"],
                    SinglePaymentDateFrom = context.Request["SinglePaymentDateFrom"],
                    SinglePaymentDateEnd = context.Request["SinglePaymentDateEnd"],
                    PageIndex = Convert.ToInt32(context.Request["pageIndex"]),
                    PageSize = Convert.ToInt32(context.Request["pageSize"]),
                    SortField = context.Request["sortField"],
                    SortOrder = context.Request["sortOrder"]
                };
                var json = bll.GetInitPayList(qcmodel);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void GetInitPayInfo(HttpContext context)
        {
            try
            {
                var id = context.Request["InitPayId"];
                if (string.IsNullOrEmpty(id)) return;
                var json = new InitPayBLL().GetInitPayInfo(id);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void GetInitPayDetailList(HttpContext context)
        {
            try
            {
                var bll = new InitPayBLL();
                var qcmodel = new InitPayDetailQcEntity
                {
                    InitPayId = context.Request["InitPayId"]
                };
                var json = bll.GetInitPayDetailList(qcmodel);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void AddInitPay(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new InitPayBLL().AddInitPay(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void ModifyInitPay(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new InitPayBLL().ModifyInitPay(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void RemoveInitPay(HttpContext context)
        {
            try
            {
                var id = context.Request["InitPayId"];
                if (string.IsNullOrEmpty(id)) return;
                var json = new InitPayBLL().RemoveInitPay(id);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}